//
//  LrcLine.m
//  老司机发车了标准版
//
//  Created by SuperNing on 16/8/10.
//  Copyright © 2016年 斌. All rights reserved.
//

#import "LrcLine.h"

@implementation LrcLine

- (instancetype)initWithLrcLineString:(NSString *)lrcLineString
{
    if (self = [super init]) {
        // [01:02.38]想你时你在天边
        NSArray *lrcArray = [lrcLineString componentsSeparatedByString:@"]"];
        self.text = lrcArray[1];
        self.time = [self timeWithString:[lrcArray[0] substringFromIndex:1]];
    }
    return self;
    
}

+ (instancetype)LrcLineString:(NSString *)lrcLineString
{
    return [[self alloc] initWithLrcLineString:lrcLineString];
}

- (NSTimeInterval)timeWithString:(NSString *)timeString
{
    // 01:02.38
    NSInteger min = [[timeString componentsSeparatedByString:@":"][0] integerValue];
    if (timeString.length <= 4) {
        NSInteger sec = 0;
        NSInteger hs = [[timeString componentsSeparatedByString:@"."][0] integerValue];
        return min * 60 + sec + hs * 0.01;
    }else{
        
        NSInteger sec = [[timeString substringWithRange:NSMakeRange(3, 2)] integerValue];
        NSInteger hs = [[timeString componentsSeparatedByString:@"."][0] integerValue];
        return min * 60 + sec + hs * 0.01;

    }

    
}



@end
